<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>后台管理系统</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="/dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. We have chosen the skin-blue for this starter
    page. However, you can choose any other skin. Make sure you
    apply the skin class to the body tag so the changes take effect.
    -->
    <link rel="stylesheet" href="/dist/css/skins/skin-blue.min.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
<#include "header.ftl" />
<#include "sidebar.ftl" />
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper" id="app">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                内容管理
                <small>社区管理</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 内容管理</a></li>
                <li class="active">社区管理</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="invoice">
            <!-- info row -->
            <div class="row invoice-info">
                <div class="col-sm-4 invoice-col">
                    <b>帖子详情</b><br>
                    <br>
                    <b>用户昵称:</b> ${(post.nickname)!}<br>
                    <b>头像:</b> ${(post.avatarUrl)!}<br>
                    <b>发帖时间:</b> ${(post.postDate)!}<br>
                    <b>最新跟帖时间:</b> ${(post.followDate)!}<br>
                </div>
                <!-- /.col -->
                <div class="col-sm-4 invoice-col">
                    <b>主贴内容</b><br>
                    <br>
                    ${(post.content)!}<br>
                </div>
                <!-- /.col -->
                <div class="col-sm-4 invoice-col">
                    <b>其他信息</b><br>
                    <br>
                    <b>阅读数:</b> ${(post.readNum)!}<br>
                    <b>点赞数:</b> ${(post.likeNum)!}<br>
                    <b>跟帖数:</b> ${(post.followNum)!}<br>
                    <b>真实用户跟帖:</b> ${(post.realFollow)!?string('有','无')}<br>
                    <b>可见性:</b> ${(post.visibility)!?string('全部用户可见','用户自己可见')}<br>
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->

            <!-- Form row -->
            <div class="row">
                <form id="posts" method="post" action="/posts/update">
                    <input type="hidden" id="postId" name="postId" value="${(post.id)!''}" />
                    <div class="form-group">
                        <label for="readNum" class="col-sm-2 control-label">设置阅读数:</label>
                        <div class="col-sm-1">
                            <input id="readNum" name="readNum" class="form-control" form="posts" type="text">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="likeNum" class="col-sm-2 control-label">设置点赞数:</label>
                        <div class="col-sm-1">
                            <input id="likeNum" name="likeNum" class="form-control" form="posts" type="text">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="visibility" class="col-sm-2 control-label">设置帖子可见性:</label>
                        <label class="radio-inline">
                            <input type="radio" name="visibility" id="visibility1" value="true" ${(post.visibility)?string("checked","")}> 全部用户可见
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="visibility" id="visibility2" value="false" ${(post.visibility)?string("","checked")}> 用户自己可见
                        </label>
                    </div>
                    <div class="form-group">
                        <label for="content" class="col-sm-2 control-label">主贴内容</label>

                        <div class="col-sm-10">
                            <textarea id="content" name="content" class="form-control" rows="3" form="posts"
                                                  placeholder="主贴内容不超过200个字"></textarea>
                        </div>
                    </div>
                    <p class="pull-right">
                        <input type="submit" class="btn btn-danger btn-lg" value="确认并返回" />
                        <a href="/posts" class="btn btn-info btn-lg" role="button">返回</a>
                    </p>
                </form>
            </div>
            <!-- /.row -->

            <div class="box-header">
                <button type="button" class="btn btn-info" @click="addPost()"><i class="fa fa-user-plus"></i> 新增跟帖
                </button>
            </div>

            <div class="row">
                <table class="table table-hover">
                    <tr>
                        <th>ID</th>
                        <th>用户昵称</th>
                        <th>跟帖内容</th>
                        <th>操作</th>
                    </tr>
                    <tr v-for="subPost in subPosts">
                        <td>{{ subPost.id }}</td>
                        <td>{{ subPost.nickname }}</td>
                        <td style="max-width: 100px; overflow: hidden; text-overflow:ellipsis; white-space: nowrap;">{{ subPost.content }}</td>
                        <td>
                            <button type="button" class="btn btn-danger" @click="delPost(subPost.id)">删除</button>
                        </td>
                    </tr>
                </table>
                <modal :show.sync="showSubPostModal" title="新增跟帖" effect="fade">
                    <div slot="modal-body" class="modal-body">
                        <form class="form-horizontal">
                            <div class="form-group">
                                <label for="inputPhotoUrl" class="col-sm-2 control-label">用户昵称</label>

                                <div class="col-sm-10">
                                    <select v-model="subPost.nickname">
                                        <option value="">--选择昵称--</option>
                                    <#list fakeUsers as fakeUser>
                                        <option value="${(fakeUser.id)!''}">${(fakeUser.nickname)!''}</option>
                                    </#list>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="inputPhotoUrl" class="col-sm-2 control-label">跟帖内容</label>

                                <div class="col-sm-10">
                                        <textarea id="inputPhotoUrl" class="form-control" rows="3" v-model="subPost.content"
                                                  placeholder="主贴内容不超过200个字"></textarea>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div slot="modal-footer" class="modal-footer">
                        <button type="button" class="btn btn-default" @click='closePostModal()'>关闭</button>
                        <button type="button" class="btn btn-primary" @click='doAddPost()'>保存</button>
                    </div>
                </modal>
            </div>

            <div class="box-footer clearfix">
                <ul class="pagination pagination-sm no-margin pull-right">
                    <li class="first" v-bind:class="{'disabled': first}">
                        <a v-if="first">首页</a>
                        <a v-else @click="toFirst()">首页</a>
                    </li>
                    <li class="prev" v-bind:class="{'disabled': first}">
                        <a v-if="first">上一页</a>
                        <a v-else @click="toPrev()">上一页</a>
                    </li>
                    <template v-for="index in totalPages">
                        <li class="paginate_button {{classRenderer(index)}}">
                            <a @click="jumpTo(index)">{{ index + 1 }}</a>
                        </li>
                    </template>
                    <li class="next" v-bind:class="{'disabled': last}">
                        <a v-if="last">下一页</i></a>
                        <a v-else @click="toNext()">下一页</i></a>
                    </li>
                    <li class="last" v-bind:class="{'disabled': last}">
                        <a v-if="last">末页</a>
                        <a v-else @click="toLast()">末页</a>
                    </li>
                </ul>
            </div>
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->

<#include "footer.ftl" />
</div>
<!-- ./wrapper -->

<!-- REQUIRED JS SCRIPTS -->

<!-- jQuery 2.2.0 -->
<script src="/plugins/jQuery/jQuery-2.2.0.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="/bootstrap/js/bootstrap.min.js"></script>
<!-- AdminLTE App -->
<script src="/dist/js/app.min.js"></script>
<#--Vue.js-->
<script src="/vue/vue.min.js"></script>
<script src="/vue/vue-resource.min.js"></script>
<script src="/vue/vue-strap.min.js"></script>
<script>
    var modal = VueStrap.modal;
    new Vue({
        el: '#app',
        data: {
            subPosts: [],
            showSubPostModal: false,
            subPost: {},
            totalPages: "",
            totalElements: "",
            last: "",
            size: "",
            number: 0,
            sort: [],
            first: "",
            numberOfElements: ""
        },
        components: {
            modal
        },
        ready: function () {
            this.$http.get("/subPosts/${(post.id)!}", function (data) {
                this.subPosts = data.content;
                this.first = data.first;
                this.last = data.last;
                this.totalPages = data.totalPages;
                this.number = data.number;
            })
        },
        methods: {
            classRenderer: function (index) {
                if (index == this.number) {
                    return 'active';
                }
                return '';
            },
            toFirst: function () {
                this.getList(0);
            },
            toLast: function () {
                this.getList(this.totalPages - 1);
            },
            toPrev: function () {
                this.getList(this.number - 1);
            },
            toNext: function () {
                this.getList(this.number + 1);
            },
            jumpTo: function (index) {
                this.getList(index);
            },
            getList: function (page) {
                this.$http.get("/subPosts/${(post.id)!}", {page: page}).then(function (response) {
                    var data = response.data;
                    this.subPosts = data.content;
                    this.first = data.first;
                    this.last = data.last;
                    this.totalPages = data.totalPages;
                    this.number = data.number;
                }, function (data) {
                    console.log(data);
                })
            },
            delPost: function(id) {
                this.$http.delete("/subPosts/" + ${(post.id)!} + "/sub/" + id).then(function(data) {
                    this.getList(0);
                })
            },
            addPost: function () {
                this.showSubPostModal = true;
            },
            doAddPost: function () {
                var subPost = {
                    id: ${(post.id)!},
                    nickname: this.subPost.nickname,
                    content: this.subPost.content
                }
                this.$http.post("/subPosts", subPost).then(function (data) {
                    this.getList(this.number);
                    this.showSubPostModal = false;
                });
                this.subPost.nickname = null;
                this.subPost.content = null;
            },
            closePostModal: function () {
                this.subPost.nickname = null;
                this.subPost.content = null;
                this.showSubPostModal = false;
            }
        }
    })
</script>

</body>
</html>